<?php

/**
 * @BelongProject: flami_mangers
 * @Author: Zwc
 * @CreateTime: 2025-11-12 19:36:20
 * @Description: TODO
 */

namespace App\Domain;

use function PhalApi\DI;

class LangDataDomain
{
    /**
     * 获取语言
     * @param $langId
     * @return array
     */
    public static function getLangData($langId) {
        $data = DI()->notorm->lang_data
            ->where('del_flag = 0 and lang_id = ' . $langId)
            ->fetchAll()
        ;

        if (empty($data)) {
            $langId = self::getDefaultLangData();
            $data = DI()->notorm->lang_data
                ->where('del_flag = 0 and lang_id = ' . $langId)
                ->fetchAll()
            ;
        }
        return array_column($data, 'value', 'type');
    }

    /**
     * 获取IOS的多语言
     * @param $langId
     * @return array
     */
    public static function getLangDataIos($langId): array
    {
        $data = DI()->notorm->lang_data
            ->where('del_flag = 0 and lang_id = ' . $langId)
            ->fetchAll()
        ;
        $basicMap = [];
        if ($langId != 266) {
            $basicData = DI()->notorm->lang_data
                ->where('del_flag = 0 and lang_id = 266')
                ->fetchAll()
            ;
            $basicMap = array_column($basicData, 'value', 'type');
        }

        if (empty($data)) {
            $langId = self::getDefaultLangData();
            $data = DI()->notorm->lang_data
                ->where('del_flag = 0 and lang_id = ' . $langId)
                ->fetchAll()
            ;
        }
        $resData = [];
        if ($langId != 266) {
            foreach ($data as $val) {
                if (isset($basicMap[$val['type']])) {
                    $resData[$basicMap[$val['type']]] = $val['value'];
                }
            }
        }else {
            foreach ($data as $val) {
                $resData[$val['value']] = $val['value'];
            }
        }

        return $resData;
    }


    public static function getDefaultLangData()
    {
        $cond = 'type = 1 and is_default = 1';
        $data = DI()->notorm->country
            ->where($cond)
            ->fetchOne();
        if ($data) {
            return $data['id'];
        }else {
            return 306;
        }
    }


}